/********************************************
 *      队列
 * Created by zlj on 2024/6/26.
********************************************/
#include "SeqQueue.h"

void InitSeqQueue(Queue *q)
{
    q->base = QUEUE_LEN;
    assert(q->base != NULL);
    q->front = q->rear = 0;
}

void EnSeqQueue(Queue *q, ElemType x)
{
    if (q->rear >= QUEUE_MAXSIZE)
    {
        printf("not enough space to insert data . \n");
        return;
    }
    q->base[q->rear++] = x; //如果还有存储空间,将数据入队
}

void DeSeqQueue(Queue *q)
{
    if (q->front == q->rear)
    {
        printf("not data to pop . \n");
        return;
    }
    q->front++; //出队操作
}

void SeqQueue_Show(Queue *q)
{
    for (int i = q->front; i < q->rear; ++i)
    {
        printf("%d ", q->base[i]);
    }
    printf("\n");
}

void SeqQueue_Get_Front(Queue *q, ElemType *v)
{
    if (q->front == q->rear)
        return;
    *v = q->base[q->front];
}

int SeqQueue_Length(Queue *q)
{
    return (q->rear - q->front);
}

void SeqQueue_Clear(Queue *q)
{
    q->front = q->rear = 0;
}

void SeqQueue_Destory(Queue *q)
{
    free(q->base);
    q->base = NULL;
}